#ifndef _X_FIELD_H
#define _X_FIELD_H
#include <iostream>
#include <string.h>
namespace x_3rd
{
    class Field{
        public:
            enum FIELD_DATA_TYPE{
                M_FIELD_TYPE_INT,
                M_FIELD_TYPE_STR,
                M_FIELD_TYPE_BLOB,
                M_FIELD_TYPE_FLOAT,
                M_FIELD_TYPE_UNKOWN
            };
            Field(std::string str_name,FIELD_DATA_TYPE str_type):name(str_name),type(str_type),value(""){}
            Field():name(""),type(M_FIELD_TYPE_UNKOWN),value(""){}
            ~Field(){}
        public:
            void setName(std::string str_name){ name = str_name;}
            void setValue(std::string str_value){ value = str_value;}
            void setValueStrLen(uint32_t str_len){ value_len = str_len;}
            uint32_t getValueStrLen() { return value_len;}
            void setType(FIELD_DATA_TYPE str_type) { type = str_type;}
            std::string getName() {return name;}
        public:
            std::string GetString(){return value;}
            float GetFloat() const { return !value.empty() ? static_cast<float>(atof(value.c_str())) : 0; }
            bool GetBool() const { return !value.empty() ? atoi(value.c_str()) > 0 : false; }
            int32_t GetInt32() const { return !value.empty() ? static_cast<int32_t>(atol(value.c_str())) : 0; }
            uint8_t GetUInt8() const { return !value.empty() ? static_cast<uint8_t>(atol(value.c_str())) : 0; }
            uint16_t GetUInt16() const { return !value.empty() ? static_cast<uint16_t>(atol(value.c_str())) : 0; }
            int16_t GetInt16() const { return !value.empty() ? static_cast<int16_t>(atol(value.c_str())) : 0; }
            uint32_t GetUInt32() const { return !value.empty() ? static_cast<uint32_t>(atol(value.c_str())) : 0; }
            uint64_t GetUInt64() const
            {
                if(!value.empty())
                {
                    uint64_t data;
                    sscanf(value.c_str(),"%lu",&data);
                    return data;
                }
                else
                    return 0;
            }
        private:
            std::string name;
            std::string value;
            uint32_t    value_len;
            FIELD_DATA_TYPE  type;
    };
}

#endif